<?php
include('../../include/functions.inc.php');
$idAssign = getParam('ID');
$idCycle = getParam('CYCLE');
$teacherAssign = $db->query_select("cllg_teacher_assign", "ID=" . sqlValue($idAssign, "int"));
$teacherAssign = $teacherAssign[0];
$sqlStudentAssign = "SELECT a.FK_STUDENT ID,
                            b.SCORE,
                            b.MIN_SCORE,
                            b.APROVED 
                     FROM   cllg_student_assign a,
                            cllg_assign_detail b
                     WHERE  a.STATUS = 1 
                     AND    a.ID = b.FK_ASSIGN 
                     AND    a.FK_CYCLE = " . sqlValue($idCycle, "int") . "
                     AND    b.FK_COURSE = " . sqlValue($teacherAssign["FK_COURSE"], "int") . "
                     AND    b.SECTION = " . sqlValue($teacherAssign["SECTION"], "text");

$sqlAll = "SELECT   a.ID, 
                    a.FIRST_NAME,
                    a.SECOND_NAME,
                    a.LAST_NAME, 
                    b.SCORE,
                    b.MIN_SCORE 
            FROM    cllg_student a,
                    (" . $sqlStudentAssign . ") b 
            WHERE   a.ID = b.ID
            ORDER   BY a.ID";
$r = $db->queryToArray($sqlAll);
$porcent = 100;
$showName = true;
if (isset($_POST['print'])) {
    $porcent = 50;
    $showName = false;
}
?>
<table width="<?= $porcent ?>%" border="0" cellspacing="0" cellpadding="0" class="table table-bordered table-hover table-striped">
    <tr>
        <th width="20%" scope="col">No. Carnet</th>
        <?php if ($showName) { ?>
            <th width="50%" align="left" scope="col">Estudiante</th>
        <?php } ?>
        <th width="30%" align="left" scope="col">Nota</th>
    </tr>
    <?php foreach ($r as $a) { ?>
        <tr>
            <td><?php echo $a["ID"]; ?></td>
            <?php if ($showName) { ?>
                <td><?php echo $a["FIRST_NAME"] . " " . $a["SECOND_NAME"] . " " . $a["LAST_NAME"]; ?></td>
            <?php } ?>
            <?php
            $nota = $a["SCORE"];
            $strStyle = '';
            $notaminima = $a["MIN_SCORE"];
            if ($notaminima > $nota) {
                $strStyle = "style='color:red'";
            }
            if ($nota == 0) {
                $nota = "PENDIENTE";
            } else {
                $nota = number_format($nota, 2);
            }
            ?>
            <td <?php print $strStyle; ?>><?php echo $nota; ?></td>
        </tr>
        <?php
    }
    ?>
</table>